package pers.hwh.testmongodb.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Data
@TableName(value = "`user`")
@AllArgsConstructor
@NoArgsConstructor
@Document("user")
//@CompoundIndexes(@CompoundIndex(name = "name_age_idx",def = "{'name':1,'age',-1}"))
public class User {
	@TableId(value = "uid", type = IdType.ASSIGN_ID)
	@Id
	private String uid;

	// @Transient
	//	@Indexed
	@TableField(value = "`name`")
	private String name;

	@TableField(value = "`password`")
	private String password;

	@TableField(value = "age")
	private Integer age;

	@TableField(value = "salary")
	@Field(targetType = FieldType.DECIMAL128)
	private BigDecimal salary;

	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	@TableField(value = "birthday")
	private Date birthday;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@TableField(value = "register_time")
	private Date registerTime;
}